home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / RICHEDPR.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  6KB  |  221 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1991, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.10  $
  6. //
  7. // Definition of classes supporting Printing/PrintPreview for TRichEdit
  8. //----------------------------------------------------------------------------
  9. #if !defined(OWL_RICHEDPR_H)
  10. #define OWL_RICHEDPR_H
  11.  
  12. #if !defined(BI_PLAT_WIN32)
  13. # error OWL: Rich Edit preview support is only available for WIN32 targets
  14. #endif
  15.  
  16. #if !defined(OWL_PRINTER_H)
  17. # include <owl/printer.h>
  18. #endif
  19. #if !defined(OWL_PREVIEW_H)
  20. # include <owl/preview.h>
  21. #endif
  22. #if !defined(OWL_PREVWIN_H)
  23. # include <owl/prevwin.h>
  24. #endif
  25. #if !defined(OWL_LAYOUTWI_H)
  26. # include <owl/layoutwi.h>
  27. #endif
  28. #if !defined(OWL_RICHEDIT_H)
  29. # include <owl/richedit.h>
  30. #endif
  31.  
  32. #if defined(BI_NAMESPACE)
  33. namespace OWL {
  34. #endif
  35.  
  36. // Generic definitions/compiler options (eg. alignment) preceeding the 
  37. // definition of classes
  38. #include <services/preclass.h>
  39.  
  40. //
  41. //
  42. template <class T>
  43. class TDynArray {
  44.   public:
  45.     TDynArray(uint limit, uint delta);
  46.    ~TDynArray();
  47.     T&          operator[](uint index);
  48.  
  49.   protected:
  50.     void        SetLimit(uint aLimit);
  51.  
  52.   private:
  53.     T*          items;              // Pointer to array of T
  54.     uint        limit;              // Size array is allocated for
  55.     uint        delta;              // Inc. delta for resizing
  56. };
  57.  
  58. //
  59. //
  60. //
  61. template<class T>
  62. TDynArray<T>::TDynArray(uint aLimit, uint aDelta)
  63. : items(0), limit(0), delta(aDelta)
  64. {
  65.   SetLimit(aLimit);
  66. }
  67.  
  68. //
  69. //
  70. //
  71. template<class T> TDynArray<T>::~TDynArray()
  72. {
  73.   SetLimit(0);
  74. }
  75.  
  76. //
  77. //
  78. //
  79. template<class T> T& TDynArray<T>::operator[](uint index)
  80. {
  81.   // Grow if necessary
  82.   //
  83.   while(index >= limit)
  84.    SetLimit(limit + delta);
  85.  
  86.   return items[index];
  87. }
  88.  
  89. //
  90. //
  91. //
  92. template<class T> void TDynArray<T>::SetLimit(uint aLimit)
  93. {
  94.   if (aLimit != limit) {
  95.     T* aItems;
  96.  
  97.     if (aLimit == 0) {
  98.       aItems = 0;
  99.     }
  100.     else {
  101.       // NOTE: T must have default constructor and proper copy
  102.       //       semantics (copy ctr and assignment operator)..
  103.       //
  104.       aItems = new T[aLimit];
  105.  
  106.       // Copy over the items already in array
  107.       //
  108.       for (uint i=0; i<limit && i<aLimit; i++)
  109.         aItems[i] = items[i];
  110.     }
  111.  
  112.     delete [] items;
  113.     items = aItems;
  114.     limit = aLimit;
  115.   }
  116. }
  117.  
  118.  
  119. #if defined(BI_COMP_BORLANDC)
  120. # if defined(_OWLDLL) || defined(BI_APP_DLL)
  121. //
  122. // Export template of TDynArray<int> when building ObjectWindows DLL 
  123. // and provide import declaration of DLL instance for users of the class.
  124. //
  125. template class _OWLCLASS TDynArray<int>;
  126. # endif //  _OWLDLL || BI_APP_DLL
  127. #endif  //  BI_COMP_BORLANDC
  128.  
  129. //
  130. // class TRichEditPreviewFrame
  131. // ~~~~~ ~~~~~~~~~~~~~~~~~~~~~
  132. // TRichEditPreviewFrame is a window object which contains preview pages
  133. // displaying data from a rich edit control. It contains a simple preview
  134. // toolbar and one or two preview pages.
  135. //
  136. class _OWLCLASS TRichEditPreviewFrame : public TPreviewWin {
  137.   public:
  138.     TRichEditPreviewFrame(TWindow* parentWindow,  /* Parent object  */
  139.                           TPrinter& printer,      /* Printer object */
  140.                           TPrintout& printout,    /* Printout object*/
  141.                           TRichEdit& richEdit,    /* RichEdit ctrl. */
  142.                           const char far* title,  /* Title of window*/
  143.                           TLayoutWindow* client); /* Client window  */  
  144.  
  145.   protected:
  146.     TPreviewPage* GetNewPreviewPage(TWindow* parent,
  147.                                     TPrintout& printout,
  148.                                     TPrintDC&  prndc,
  149.                                     TSize&     printExtent,
  150.                                     int        pagenum = 1);
  151. };
  152.  
  153. //
  154. // class TRichEditPagePreview
  155. // ~~~~~ ~~~~~~~~~~~~~~~~~~~~
  156. // TRichEditPagePreview is a window which displays rich edit data formatted
  157. // for a particular printer DC.
  158. //
  159. class _OWLCLASS TRichEditPagePreview : public TPreviewPage {
  160.   public:
  161.     TRichEditPagePreview(TWindow* parent, TPrintout& printout,
  162.                          TPrintDC&  prndc, TSize& printExtent,
  163.                          int pagenum = 1);
  164.   protected:
  165.     void  Paint(TDC& dc, bool, TRect& clip);
  166. };
  167.  
  168. //
  169. // class TRichEditPrintout
  170. // ~~~~~ ~~~~~~~~~~~~~~~~~
  171. // TRichEditPrintout encapsulates the information to print/preview data from
  172. // a rich edit control. For example, it holds the offset of pages, the range
  173. // of data to be printer/previewed etc. etc.
  174. //
  175. class _OWLCLASS TRichEditPrintout : public TPrintout {
  176.   public:
  177.     TRichEditPrintout(TPrinter& printer,
  178.                       TRichEdit& richEdit,
  179.                       const char far* title);
  180.    ~TRichEditPrintout();
  181.  
  182.     // Overriden virtual methods of TPrintout
  183.     //
  184.     void          GetDialogInfo (int& minPage, int& maxPage,
  185.                                  int& selFromPage, int& selToPage);
  186.     void          SetPrintParams(TPrintDC* dc, TSize pageSize);
  187.     bool          HasPage(int pageNumber);
  188.     void          BeginPrinting();
  189.     void          PrintPage(int page, TRect& rect, uint flags);
  190.     void          EndPrinting();
  191.     void          CleanupPrintParams();
  192.  
  193.     // Helper methods
  194.     //
  195.     int           PageOfOffset(int offset);
  196.  
  197.   protected:
  198.  
  199.  
  200.     TRichEdit&     RichEdit;              // Ref. to associated control  
  201.     TPrinter&      Printer;               // Ref. to associated printer
  202.     TSize          SizePhysPage;          // Physical size of printer (pels)
  203.     TSize          SizePhysInch;          // Size of printer in inches
  204.     TSize          Margins;               // Size of margins
  205.     TFormatRange   FmtRange;              // Range of text to format
  206.     bool           FlushCache;            // Have cached formatted data
  207.     int            TextLen;               // Length of text formatted
  208.     int            PageCount;             // Number of pages formatted
  209.     TDynArray<int> PageIndices;           // Index of page offsets
  210. };
  211.  
  212. // Generic definitions/compiler options (eg. alignment) following the 
  213. // definition of classes
  214. #include <services/posclass.h>
  215.  
  216. #if defined(BI_NAMESPACE)
  217. } // namespace OWL
  218. #endif
  219.  
  220. #endif  // OWL_REDITPRI_H
  221.